/**
 * @Author: cest
 * @Date: 2022-08-04 09:46:53
 * @LastEditTime: 2022-08-04 15:58:12
 * @LastEditors: cest
 * @FilePath: /vue3-todo-list/src/hooks/useState.js
 * @Description: 编辑描述内容
 */
import { mapState, createNamespacedHelpers } from 'vuex'
import { mapper } from './useMapper'

export const useState = (spaceName, mapArry) => {
  let mapArryTemp = mapArry
  let mapFn = mapState
  if (typeof spaceName === 'string' && spaceName.length > 0) {
    mapFn = createNamespacedHelpers(spaceName).mapState
  } else {
    mapArryTemp = spaceName
  }
  return mapper(mapArryTemp, mapFn)
}

export default useState
